/**
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaginsDialog.java
 *
 * Created on 07.12.2008, 14:33:17
 */
package trim.gui.testing;

import javax.swing.JFileChooser;
import trim.gui.testing.models.PlaginsTableModel;

/**
 *
 * @author Дмитрий
 */
public class PlaginsDialog extends javax.swing.JDialog
{

  PlaginManager plaginManager;
  PlaginsTableModel plaginsTableModel;

  /** Creates new form PlaginsDialog */
  public PlaginsDialog(java.awt.Frame parent,PlaginManager plaginManager,boolean modal)
  {
    super(parent,"Plagins",modal);
    this.plaginManager=plaginManager;
    this.plaginsTableModel=new PlaginsTableModel(plaginManager);
    initComponents();
  }

  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    splitPanePlagins = new javax.swing.JSplitPane();
    jPanel2 = new javax.swing.JPanel();
    btAddPlagin = new javax.swing.JButton();
    jScrollPane2 = new javax.swing.JScrollPane();
    listPlagins = new javax.swing.JList();
    jButton1 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    trimClassesTable = new javax.swing.JTable();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 683, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 0, Short.MAX_VALUE)
    );

    splitPanePlagins.setDividerLocation(200);

    btAddPlagin.setText("Добавить");
    btAddPlagin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btAddPlaginActionPerformed(evt);
      }
    });

    listPlagins.setModel(plaginsTableModel);
    listPlagins.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        listPlaginsValueChanged(evt);
      }
    });
    jScrollPane2.setViewportView(listPlagins);

    jButton1.setText("Удалить");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addComponent(btAddPlagin)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
        .addComponent(jButton1))
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(btAddPlagin)
          .addComponent(jButton1)))
    );

    splitPanePlagins.setLeftComponent(jPanel2);

    trimClassesTable.setModel(plaginsTableModel);
    jScrollPane1.setViewportView(trimClassesTable);

    splitPanePlagins.setRightComponent(jScrollPane1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(splitPanePlagins, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 683, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addComponent(splitPanePlagins, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
        .addGap(0, 0, 0)
        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void btAddPlaginActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btAddPlaginActionPerformed
    {//GEN-HEADEREND:event_btAddPlaginActionPerformed
      JFileChooser fileChooser=new JFileChooser(AppState.CURRENT_FILE);
      try
      {
        int returnVal=fileChooser.showOpenDialog(this);
        if(returnVal==JFileChooser.APPROVE_OPTION)
        {
          AppState.CURRENT_FILE=fileChooser.getSelectedFile().getParentFile();
          plaginManager.loadPlagin(fileChooser.getSelectedFile());
          plaginsTableModel.fireTableDataChanged();
          plaginsTableModel.fireListDataChanged();
          plaginManager.savePlagins();
        }
      }catch(Exception ex)
      {
        ex.printStackTrace();
      }
    }//GEN-LAST:event_btAddPlaginActionPerformed

    private void listPlaginsValueChanged(javax.swing.event.ListSelectionEvent evt)//GEN-FIRST:event_listPlaginsValueChanged
    {//GEN-HEADEREND:event_listPlaginsValueChanged
      int i=listPlagins.getSelectedIndex();
      plaginsTableModel.setPlaginIndex(i);
}//GEN-LAST:event_listPlaginsValueChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      int i=listPlagins.getSelectedIndex();
      plaginsTableModel.removePlagin(i);

    }//GEN-LAST:event_jButton1ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton btAddPlagin;
  private javax.swing.JButton jButton1;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JList listPlagins;
  private javax.swing.JSplitPane splitPanePlagins;
  private javax.swing.JTable trimClassesTable;
  // End of variables declaration//GEN-END:variables
}
